"""
除n取余法
"""


def func(num, n):
    str_list = []
    dic = {
        k: v for k, v in enumerate('0123456789ABCDEF')
    }
    while True:
        if num == 0:
            break
        next_num = num // n  # 商
        add_num = num % n  # 余数
        str_list.insert(0, str(dic[add_num])) # 将余数添加到结果集
        num = next_num # 将计算数字赋值为商
    return ''.join(str_list)


print(func(8, 2))
